Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.
Name | setPWMResolution() |
||||
---|---|---|---|---|---|
Examples | int brightness = 0; // LED brightness int increment = 5; // brightness increment void setup() { pinMode(4, OUTPUT); // set PWM pin as output setPWMResolution(4, 10); // set PWM resolution to 10-bit (now values range in 0-1023) } void loop() { // increment brightness for next loop iteration brightness = brightness + increment; // reverse the direction of the fading // since 10-bit resolution is active, // possible values are in the range 0-1023 if (brightness <= 0 || brightness >= 1023) { increment = -increment; } // keep brightness in the range brightness = constrain(brightness, 0, 1023); analogWrite(4, brightness); // set the PWM output // wait for 20 milliseconds to see the dimming effect delay(20); } |
||||
Description | The setPWMResolution() method sets the PWM output resolution of a PWM output pin. On Wiring v1 boards the PWM capable pins are: 29, 30, 31, 35, 36 and 37. On Wiring S board the PWM capable pins are: 4, 5, 6, 7, 19 and 20. Possible PWM bits resolution are: 8-bit (default for all PWM outputs, allowing values from 0-255), 9-bit (allowing values from 0-511) and 10-bit (allowing values from 0-1023). IMPORTANT Note: Not all pins support 9 and 10 bit resolution. On Wiring v1 boards the 9 and 10 bit PWM resolution capable pins are: 29, 30, 31, 35, 36 and 37. On Wiring S board the 9 and 10 bit PWM resolution capable pins are: 4 and 5. Pins 6, 7, 19 and 20 are 8 bit resolution only. PWM pins are internally grouped/managed by timers, a single timer can handle 2 or 3 pins, which means that changing operation settings like resolution or prescale for one pin will change it as well for the pins sharing the same timer. For example setting PWM bit resolution to 10 bits for pin 29 on the Wiring v1 boards will automatically change it for pins 30 and 31 (29, 30 and 31 are controlled by the same timer). On Wiring v1 boards timer PWM pin groups are: [29, 30, 31] and [35, 36, 37]. On Wiring S board timer PWM pin groups are: [4,5] [6,7] and [19, 20]. | ||||
Syntax | setPWMResolution(pin, bitresolution)
|
||||
Parameters |
|
||||
Returns | None | ||||
Usage | Application | ||||
Related | analogWrite() noAnalogWrite() setPWMPrescale() analogRead() |